package fr.emn.integration.synthese.presentation;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import fr.emn.integration.synthese.abstraction.Cours;
import fr.emn.integration.synthese.abstraction.Evaluation;
import fr.emn.integration.synthese.abstraction.Groupe;
import fr.emn.integration.synthese.controle.ControlJButtonSaveEval;
import fr.emn.integration.synthese.controle.ControlJButtonSaveGroupe;

public class EvalDialog extends JDialog {

	private static final long serialVersionUID = 1L;

	private JTextField date;
	private JComboBox type;

	public String getDate() {
		try {
			String i = date.getText();
			if (i.equals(null)) {
				JOptionPane.showMessageDialog(this, "On ne peut pas!", "Erreur!", JOptionPane.ERROR_MESSAGE);
				i = null;
			}
			return i;
		} catch (NumberFormatException e) {
			JOptionPane.showMessageDialog(this, "On ne peut pas!", "Erreur!",
					JOptionPane.ERROR_MESSAGE);
			return null;
		}
	}
	
	public String getTypeE() {
		try {
			String i = type.getSelectedItem().toString();
			if (i.equals(null)) {
				JOptionPane.showMessageDialog(this, "On ne peut pas!", "Erreur!", JOptionPane.ERROR_MESSAGE);
				i = null;
			}
			return i;
		} catch (NumberFormatException e) {
			JOptionPane.showMessageDialog(this, "On ne peut pas!", "Erreur!",
					JOptionPane.ERROR_MESSAGE);
			return null;
		}
	}

	

	public EvalDialog(Frame parent, Cours modele, boolean creation) {
		super(parent, "Eval", true);
		this.setMinimumSize(new Dimension(200, 100));

		this.getContentPane().setLayout(new GridLayout(1, 3));

		JPanel form = new JPanel(new GridLayout(5, 1));
		form.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));

		form.add(new JLabel("DATE"));
		date = new JTextField();
		form.add(date);
		
		form.add(new JLabel("TYPE"));
		String[] val = {"Ecrit","Oral"};
		type = new JComboBox(val);
		form.add(type);

		JPanel buttons = new JPanel();
		JButton save = new JButton("OK");
		save.addActionListener(new ControlJButtonSaveEval(this, modele,creation));
		buttons.add(save);
		form.add(buttons);

		this.getContentPane().add(form);

		if (!creation) {
			Evaluation courante = modele.findEvaluation(modele.getEvaluationCourante());
			date.setText("" + courante.getDate());
			type.setSelectedItem("" + courante.getType());
		}

		this.pack();
		super.setLocationRelativeTo(parent);
	}

}
